package group.sicher.lock.constant;

import group.sicher.lock.Exception.MarsLockStoreIsEmptyException;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: aron
 * @date: 2019-08-05 17:51
 */
public class MarsMapStore {

    private static Map<String,MarsServerPattern> serverPatternMap=new HashMap<>();

    static {
        serverPatternMap.put(MarsServerPattern.SINGLE.getPattern(), MarsServerPattern.SINGLE);
        serverPatternMap.put(MarsServerPattern.CLUSTER.getPattern(), MarsServerPattern.CLUSTER);
        serverPatternMap.put(MarsServerPattern.MASTER_SLAVE.getPattern(), MarsServerPattern.MASTER_SLAVE);
        serverPatternMap.put(MarsServerPattern.REPLICATED.getPattern(), MarsServerPattern.REPLICATED);
        serverPatternMap.put(MarsServerPattern.SENTINEL.getPattern(), MarsServerPattern.SENTINEL);
    }

    /**
     * 根据字符串模式标识返回服务器模式枚举类
     * @param pattern
     * @return
     */
    public static MarsServerPattern getServerPattern(String pattern) throws MarsLockStoreIsEmptyException {
        MarsServerPattern serverPattern=serverPatternMap.get(pattern);
        if(serverPattern==null) {
            throw new MarsLockStoreIsEmptyException("没有找到相应的服务器模式,请检测参数是否正常,pattern的值为:"+pattern);
        }
        return serverPattern;
    }
}
